package com.egao.api.controller.orderB;


import com.egao.api.base.BaseApiController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageResult2;
import com.egao.common.system.entity.OperRecord;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.entity.BillFee;
import com.egao.orderB.service.BillFeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 * https://francjc.com:4332/swagger-ui.html
 */
@RequestMapping("/api/billFee")
@RestController
@Api(value = "订单运费管理",tags = {"订单运费管理"})
public class ApiBillFeeController extends BaseApiController {

    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private BillFeeService billFeeService;

    /**
     * 订单运费列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "订单运费列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "billId:订单id 必填\n" +
            "page:第几页 必填\n" +
            "type:省\n" +
            "feeName:市\n" +
            " \n" +
            "返回的内容\n" +
            "id:id\n" +
            "companyId:公司id\n" +
            "billId:订单id\n" +
            "type:类型\n" +
            "feeName:费用名称\n" +
            "price:金额\n" +
            "remark:备注\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "deleted:del(0正常 1删除)\n" +
            "",httpMethod = "POST")
    @ResponseBody
    public JSONObject list(PageResult2<T> page, BillFee billFee, HttpServletRequest request)  throws Exception{
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "订单运费列表", "订单运费列表",
                request.getServletPath(), "POST", "ApiBillFeeController.list", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return billFeeService.list(page, billFee, getLoginUser(request));
    }

    /**
     * 运费报价列表
     */
    @PostMapping("/listAll")
    @ApiOperation(value = "订单运费列表",notes = "" +
            "billId:订单id 必填\n" +
            "type:省\n" +
            "feeName:市\n" +
            "",httpMethod = "POST")
    @ResponseBody
    public List<BillFee> listAll(BillFee billFee, HttpServletRequest request)  throws Exception{
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "订单运费列表", "订单运费列表",
                request.getServletPath(), "POST", "ApiBillFeeController.list", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return billFeeService.list(billFee, getLoginUser(request));
    }


    /**
     * 添加订单运费
     */
    @PostMapping("/save")
    @ApiOperation(value = "添加订单运费",notes = "" +
            "billId:订单id 必填\n" +
            "type:类型\n" +
            "feeName:费用名称\n" +
            "price:金额\n" +
            "remark:备注\n" +
            "",httpMethod = "POST")
    @ResponseBody
    public JsonResult save(BillFee billFee, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "添加订单运费", "添加订单运费",
                request.getServletPath(), "POST", "ApiBillFeeController.save", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return billFeeService.save(billFee, getLoginUser(request));
    }
    /**
     * 批量添加订单运费
     * 取消
     */
/*    @PostMapping("/saveBatch")
    @ApiOperation(value = "批量添加订单运费",notes = "" +
            "billId:订单id 必填\n" +
            "type:类型\n" +
            "feeName:费用名称\n" +
            "price:金额\n" +
            "remark:备注\n" +
            "例子:\n" +
            "[{\"billId\":145, \"type\":\"类型3\", \"feeName\":\"费用名称3\", \"price\":\"金额3\", \"remark\":\"备注3\"},{\"billId\":145, \"type\":\"类型4\", \"feeName\":\"费用名称4\", \"price\":\"金额4\", \"remark\":\"备注4\"}]\n" +
            "",httpMethod = "POST")
    @ResponseBody*/
    public JsonResult saveBatch(@RequestBody List<BillFee> billFeeList, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "批量添加订单运费", "批量添加订单运费",
                request.getServletPath(), "POST", "ApiBillFeeController.saveBatch", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return billFeeService.saveBatch(billFeeList, getLoginUser(request));
    }


    /**
     * 订单运费修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "订单运费修改",notes = "" +
            "id 订单运费的id 必填\n" +
            "type:类型\n" +
            "feeName:费用名称\n" +
            "price:金额\n" +
            "remark:备注\n"
            ,httpMethod = "POST")
    @ResponseBody
    public JsonResult update(BillFee billFee, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "订单运费修改", "订单运费修改",
                request.getServletPath(), "POST", "ApiBillFeeController.update", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return billFeeService.update(billFee, getLoginUser(request));
    }

    /**
     * 订单运费删除
     */
    @PostMapping("/remove")
    @ApiOperation(value = "订单运费删除",notes = "" +
            "id 订单运费的id 必填\n"
            ,httpMethod = "POST")
    @ResponseBody
    public JsonResult remove(BillFee billFee, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "订单运费删除", "订单运费删除",
                request.getServletPath(), "POST", "ApiBillFeeController.remove", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return billFeeService.remove(billFee, getLoginUser(request));
    }


}
